﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LongestFlags.Question;
using System.Collections;
namespace LongestFlags.Answer
{
    class Jimson : ILongestFlag
    {
        public int GetLongestFlags(int[] iArray, out int startIndex, out int endIndex)
        {
            startIndex = 0;
            endIndex = 0;
            int length = 0;
            for (int i = 0; i < iArray.Length; i++)
            {
                for (int j = iArray.Length -1; j >=i; j--)
                {
                    List<int> arr = new List<int>();
                    for (int k = i; k <= j; k++)
                    {
                        arr.Add(iArray[k]);
                    }
                    if(IsEq(arr) && length < arr.Count)
                    {
                        startIndex = i;
                        endIndex = j;
                        length = j - i +1;
                    }
                }
            }           

            return length;
        }
        bool IsEq(List<int> array)
        {
            int Ncount = array.Where(a => a < 0).Count(); 
            int Tcount = array.Where(a => a > 0).Count();           
            return Ncount == Tcount;
        }
    } 
}